{extend name="layout/layout" /}

{block name="pagecss"}
<style>
    .left{float: left;}
    #setGroup .form-group img{width: 100px;height: 100px;}
    #setGroup .form-group .title{margin-left: 20px;font-size: 16px;}
    .form-control {display: inline;}
</style>
{/block}

{block name="content"}
<div class="row">
    <div class="col-xs-12">
        <div class="box box-success">
            <div class="box-body">
                <div id="setGroup" class="form-horizontal tenant-form pro-edit">
                <form id="setGroupForm">
                    <div class="form-group">
                        <div class="col-md-6">
                            <input type="hidden" value="{$group.id|default=''}" name="id" >
                        </div>
                    </div>
                    <div class="form-group">
                        <lable class="col-md-2 control-label">拼团商品：</lable>
                        <div class="col-md-6">
                            <div><img class="left" src="{$product.imgUrl}" alt=""><div class="left title" ><p>{$product.title}</p><p>￥{$product.currentPrice/100}</p></div></div>
                        </div>
                    </div>
                    <div class="form-group">
                        <lable class="col-md-2 control-label">拼团价：</lable>
                        {if condition="$product.specClass == 1"}  <!-- 单商品 -->
                        <div class="col-md-6">
                            <input type="number" disabled class="form-control input-xsmall" value="{$product.groupPrice/100}" name="groupPrice" maxlength="3" >元
                        </div>
                        {else /}   <!-- 多规格 -->
                        <div class="col-md-6">
                            <table>
                                <tr>{volist name="product.spec" id="ss"}<th>{$ss.specType}</th>{/volist}<th>原价(元)</th><th>拼团价(元)</th></tr>
                                {volist name="product.sub" id="vo"}
                                <tr><td>{$vo.specDetails1}</td>{notempty name="vo.specDetails2"}<td>{$vo.specDetails2}</td>{/notempty}{notempty name="vo.specDetails3"}<td>{$vo.specDetails3}</td>{/notempty}<td>￥{$vo.currentPrice/100}</td><td>￥{$vo.groupPrice/100}</td></tr>
                                {/volist}
                            </table>
                            
                        </div>
                        {/if}
                        
                    </div>
                    <div class="form-group">
                        <lable class="col-md-2 control-label">排序：</lable>
                        <div class="col-md-6">
                            <input type="number" class="form-control input-xsmall" value="{$group.sort|default=99}" name="sort" maxlength="3" >
                        </div>
                    </div>
                    <div class="form-group">
                        <lable class="col-md-2 control-label">每人限购：</lable>
                        <div class="col-md-6">
                            <input type="text" class="form-control input-xsmall" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" value="{$group.confineCount|default=''}" name="confineCount" maxlength="4" >件 <span>最低1件起，不填则不限数量</span>
                        </div>
                    </div>
                    <div class="form-group">
                        <lable class="col-md-2 control-label"><span class="required">* </span>成团人数：</lable>
                        <div class="col-md-6">
                            <input type="text" class="form-control input-xsmall" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" value="{$group.groupSuccCount|default=''}" name="groupSuccCount" maxlength="4" >人 <span> 团购成功的最低人数限制，至少2人</span>
                        </div>
                    </div>
                    <div class="form-group">
                        <lable class="col-md-2 control-label"><span class="required">* </span>成团时长：</lable>
                        <div class="col-md-6">
                            <input type="text" class="form-control input-xsmall" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" value="{$group.groupDateStr|default=''}" name="groupDateStr" maxlength="4">小时 <span>开团后开始计时</span>
                        </div>
                    </div>

                    <div class="modal-footer row">
                        <div class="col-md-2"></div>
                        <input type="hidden" name="productId" value="{$product.id}">
                        <input type="hidden" name="storeId" value="{$storeId}">
                        <div class="col-md-2"><button type="button" class="btn green" id="modal_sure_new">保 存</button>
                            <button onclick="javascript :window.close();" class="btn btn-info" type="button">关闭</button></div>
                        <div><span class="help-block "></span></div>
                    </div>
                </form>
                </div>

            </div>

        </div>
    </div>
</div>
{/block}

{block name="pagescript"}
<script src="__STATIC__/admin/js/include.js" type="text/javascript"></script>
<script>
    var setGroupSave = "{:url('admin/group/setGroupSave')}";
    $('#modal_sure_new').click(function(){
        var _data = $('#setGroupForm').serializeObject();
        if(_data.groupSuccCount < 2) {
            layer.msg('拼团人数最少2人');
            return;
        }
        if(!mdTool.validate(_data.groupDateStr,'num')) {
            layer.msg('拼团时长为非零的正整数');
            return;
        }
        if(_data.groupDateStr.length > 4) {
            layer.msg('拼团时长最长为4位');
            return;
        }
        $.ajax({
            url : setGroupSave,
            type : 'POST',
            dataType : 'json',
            contentType:"application/json; charset=utf-8",
            data : JSON.stringify(_data),
            async: false
        }).done(function(data) {
            console.log(data);
            if (data.code === '1') { 
                window.close();  //关闭本页面
                opener.location.reload();   //刷新父页面
            } else if (data.code === '2') {
                layer.msg(data.message);
            }
        });
    });
</script>
{/block}